package com.example.intenttactivity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
     private Button intentbtn1;
     private TextView txtmainl;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        setListener();
    }
    private void setListener(){
        intentbtn1.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                startActivityForResult(intent,1);

            }
        });

    }
    private void initView(){
        intentbtn1=findViewById(R.id.intentbtn1);
        txtmainl=findViewById(R.id.textmainl);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,
                                    @Nullable Intent intent){
        super.onActivityResult(requestCode,resultCode,intent);
        if (requestCode==1&&resultCode==2){
            txtmainl.setText(intent.getStringExtra("result"));
        }
    }
}
